package reg_to_dfa;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;
/*
 * 实验一第一阶段展示
 * 输入 test1.txt
 * 输出 控制台
 */
public class Test1 {
	public static void main(String[] args) throws IOException {
		try {
			FileReader reader = new FileReader("src/reg_to_dfa/test1.txt");
			BufferedReader in = new BufferedReader(reader);
			String str;
			while ((str = in.readLine()) != null) {
				// 读取正规式
				String regString = str;
				// 读取测试样例
				Vector<String> tmpVector = new Vector<String>();
				while ((str = in.readLine()) != null) {
					if (str.equals("##")) {
						break;
					}
					tmpVector.add(str);
				}
				// 由reg生成dfa
				String sufString = Reg_to_suffix.reg_to_suf(regString);
				NFA nfa = Suffix_to_nfa.suf_to_nfa(sufString);
				DFA dfa = Nfa_to_dfa.nfa_to_dfa(nfa);
				dfa = Dfa_to_minidfa.dfa_to_minidfa(dfa);
				// 对点号处理
				String pointString = "&";// 代表小数点
				if (regString.contains(pointString)) {
					dfa = Special_situation.handle_point(dfa, pointString);
				}
				// 输出二元组
				System.out.println("=================" + regString + "=================");
				for (int i = 0; i < tmpVector.size(); i++) {
					String testString = tmpVector.get(i);
					boolean bool = Is_str_fit_reg.is_str_fit_reg(testString, dfa);
					System.out.println("< "+testString + " , " + bool+" >");
				}
			}
			System.out.println("测试完毕");
			in.close();
		} catch (IOException e) {
			System.out.println("文件读取异常");
		}

	}

}
